/**
 * This is the Javascript file for the validation of the new user add form
 * 
 */
<script type="text/javascript" src="jquery-1.4.4.min.js"></script>
<script type="text/javascript" src="jquery-ui-1.8.10.custom.min.js"></script>
function validateNewUserForm() {
	// this function validates the form submitted to add a new user
	// this function returns true if validation is successful else this funtion
	// returns false
	// the fields are - userEmail, userPassword, userName, surname, expireOnDate
	var userEmail = jQuery("#userEmail").val();
	var userPassword = jQuery("#userPassword").val();
	var userName = jQuery("#userName").val();
	var surname = jQuery("#surname").val();
	var expireOnDate = jQuery("#expireOnDate").val();

	validateEmailResult = validateEmail(userEmail);
	if (validateEmailResult == false) {
		jQuery("#newUserValidationMessage").val("Email id is not valid");
		return false;
	}
	return true;
}

function validateEmail(userEmail) {
	var at = "@";
	var dot = ".";
	var lat = str.indexOf(at);
	var lstr = str.length;
	var ldot = str.indexOf(dot);
	if (str.indexOf(at) == -1) {
		return false;
	}
	if (str.indexOf(at) == -1 || str.indexOf(at) == 0
			|| str.indexOf(at) == lstr) {
		return false;
	}
	if (str.indexOf(dot) == -1 || str.indexOf(dot) == 0
			|| str.indexOf(dot) == lstr) {
		return false;
	}
	if (str.indexOf(at, (lat + 1)) != -1) {
		return false;
	}
	if (str.substring(lat - 1, lat) == dot
			|| str.substring(lat + 1, lat + 2) == dot) {
		return false;
	}
	if (str.indexOf(dot, (lat + 2)) == -1) {
		return false;
	}
	if (str.indexOf(" ") != -1) {
		return false;
	}
	return true;
}